package com.dyb.recuitment.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dyb.recuitment.entity.JobLike;
import com.dyb.recuitment.entity.Shield;
import com.dyb.recuitment.mapper.JobLikeMapper;
import com.dyb.recuitment.service.IJobLikeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 岗位收藏表 服务实现类
 * </p>
 *
 * @author 邓宇斌
 * @since 2022-02-22
 */
@Service
public class JobLikeServiceImpl extends ServiceImpl<JobLikeMapper, JobLike> implements IJobLikeService {

    @Autowired
    private JobLikeMapper jobLikeMapper;

    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    @Override
    public int add(JobLike jobLike) {
        LocalDateTime localDateTime = LocalDateTime.parse(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()), df);
        jobLike.setCreateTime(localDateTime).setUpdateTime(localDateTime);
        return jobLikeMapper.insert(jobLike);
    }

    @Override
    public int delete(JobLike jobLike) {
        LocalDateTime localDateTime = LocalDateTime.parse(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()), df);
        jobLike.setStatus(0).setUpdateTime(localDateTime);
        return jobLikeMapper.updateById(jobLike);
    }

    @Override
    public List<JobLike> selectByJobLike(JobLike jobLike) {
        jobLike.setStatus(1);
        QueryWrapper<JobLike> queryWrapper = new QueryWrapper<>(jobLike);
        return jobLikeMapper.selectList(queryWrapper);
    }

    @Override
    public List<JobLike> selectByAllLike() {
        return jobLikeMapper.selectList(new QueryWrapper<>());
    }
}
